package com.sduept.nwld.dataserver.util;

import com.sduept.nwld.dataserver.manager.transclac.Complex;

public class ElectricalUtil {
	/**
	 * 复数加法
	 * @param v2
	 * @param v1
	 */
	public static Complex complexAddition(Complex v1,Complex v2){
		Complex result = new Complex();
		double m = v1.getValue1()+v2.getValue1();
		double n = v1.getValue2()+v2.getValue2();
		result.setValue1(m);
		result.setValue2(n);
		return result;
	}
	
	/**
	 * 复数减法
	 * @param v2
	 * @param v1
	 */
	public static Complex complexSubtraction(Complex v1,Complex v2){
		Complex result = new Complex();
		double m = v1.getValue1()-v2.getValue1();
		double n = v1.getValue2()-v2.getValue2();
		result.setValue1(m);
		result.setValue2(n);
		return result;
	}
	/**
	 * 复数乘法
	 * @param v2
	 * @param v1
	 */
	public static Complex complexMultiply(Complex v1,Complex v2){
		Complex result = new Complex();
		double m = v1.getValue1()*v2.getValue1()- v1.getValue2()*v2.getValue2();
		double n = v1.getValue2()*v2.getValue1()+v1.getValue1()*v2.getValue2();
		result.setValue1(m);
		result.setValue2(n);
		return result;
	}
	/**
	 * 复数除法
	 * @param v2
	 * @param v1
	 */
	public static Complex complexDivision(Complex v1,Complex v2){
		Complex result = new Complex();
		double sbfenzi = v1.getValue1()*v2.getValue1()+ v1.getValue2()*v2.getValue2();
		double sbfenmu = v2.getValue1()*v2.getValue1()+ v2.getValue2()*v2.getValue2();
		double m =sbfenzi/sbfenmu;
		
		double xbfenzi = v1.getValue2()*v2.getValue1()-v1.getValue1()*v2.getValue2();
		double xbfenmu = sbfenmu;
		double n =xbfenzi/xbfenmu;
		result.setValue1(m);
		result.setValue2(n);
		return result;
	}
}
